﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.Synchronization.Validation.Handlers.Common;
using Sustainalytics.Synchronization.Validation.Internals;
using Sustainalytics.Synchronization.Validation.Validators;
using System;

namespace Sustainalytics.Synchronization.Validation.Handlers.Core
{
    public class CoreCorporateDataHandler : Handler<CorporateData, CoreCompanies>
    {
        public CoreCorporateDataHandler(CoreCompanies coreCompanies, ValidationMongoCollection<CorporateData> collections, CoreValidator<CorporateData> validator)
            : base(coreCompanies, collections, validator)
        {
        }

        protected override ProjectionDefinition<CorporateData> GetProjectionDefinition()
        {
            return
                Builders<CorporateData>.Projection.Include(x => x.Id)
                    .Include(x => x.CompanyName)
                    .Include(x => x.ComprehensiveEsgResearchState)
                    .Include(x => x.CoreEsgResearchState);
        }

        protected override FilterDefinition<CorporateData> GetReferenceEntityFilter(CorporateData validatedEntity)
        {
            return Builders<CorporateData>.Filter.Where(x => x.Id == validatedEntity.Id);
        }

        protected override FilterDefinition<CorporateData> GetValidatedEntityFilterDefinition(Guid companyId)
        {
            return Builders<CorporateData>.Filter.Where(x => x.Id == companyId);
        }
    }
}
